"use strict";
cc._RF.push(module, '7efa2Ur7ddBHaUWPfAVg3Gy', 'ColorBrush');
// eazax-ccc/components/effects/ColorBrush.ts

"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
/**
 * 彩色画笔（多彩 Graphics，需搭配 eazax-color-brush.effect 使用）
 * @see ColorBrush.ts https://gitee.com/ifaswind/eazax-ccc/blob/master/components/effects/ColorBrush.ts
 * @see eazax-color-brush.effect https://gitee.com/ifaswind/eazax-ccc/blob/master/resources/effects/eazax-color-brush.effect
 * @version 20210317
 */
var ColorBrush = /** @class */ (function (_super) {
    __extends(ColorBrush, _super);
    function ColorBrush() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        /** Graphics 组件 */
        _this.graphics = null;
        /** 材质 */
        _this.material = null;
        return _this;
    }
    ColorBrush.prototype.onLoad = function () {
        this.init();
        this.registerEvent();
    };
    ColorBrush.prototype.onDestroy = function () {
        this.unregisterEvent();
    };
    /**
     * 初始化
     */
    ColorBrush.prototype.init = function () {
        var graphics = this.graphics = this.node.getComponent(cc.Graphics) || this.node.addComponent(cc.Graphics);
        // 设置画笔
        graphics.strokeColor = cc.Color.WHITE;
        graphics.lineJoin = cc.Graphics.LineJoin.ROUND;
        graphics.lineCap = cc.Graphics.LineCap.ROUND;
        graphics.lineWidth = 20;
        // 设置材质上的节点尺寸参数
        // 需搭配 eazax-color-brush.effect 使用
        this.material = graphics.getMaterial(0);
        this.material.setProperty('size', this.getNodeSize());
    };
    /**
     * 订阅事件
     */
    ColorBrush.prototype.registerEvent = function () {
        this.node.on(cc.Node.EventType.TOUCH_START, this.onTouchStart, this);
        this.node.on(cc.Node.EventType.TOUCH_MOVE, this.onTouchMove, this);
    };
    /**
     * 取消事件订阅
     */
    ColorBrush.prototype.unregisterEvent = function () {
        this.node.targetOff(this);
    };
    /**
     * 点击开始
     * @param event
     */
    ColorBrush.prototype.onTouchStart = function (event) {
        var pos = this.node.parent.convertToNodeSpaceAR(event.getLocation()), graphics = this.graphics;
        graphics.moveTo(pos.x - 5, pos.y);
        graphics.circle(pos.x - 5, pos.y, 1);
        graphics.stroke();
        graphics.moveTo(pos.x - 5, pos.y);
    };
    /**
     * 点击移动
     * @param event
     */
    ColorBrush.prototype.onTouchMove = function (event) {
        var pos = this.node.parent.convertToNodeSpaceAR(event.getLocation()), graphics = this.graphics;
        graphics.lineTo(pos.x - 5, pos.y);
        graphics.stroke();
        graphics.moveTo(pos.x - 5, pos.y);
    };
    /**
     * 获取节点尺寸
     */
    ColorBrush.prototype.getNodeSize = function () {
        return cc.v2(this.node.width, this.node.height);
    };
    ColorBrush = __decorate([
        ccclass
    ], ColorBrush);
    return ColorBrush;
}(cc.Component));
exports.default = ColorBrush;

cc._RF.pop();